<script type="text/javascript">
    
    jQuery(document).ready(function(){
	$('.accordion .head').click(function() {
		$(this).parent().next().toggle('slow');
                $(this).parent().addClass('current');
		return false;
	});
        $('.accordion .target').hide();
});
</script>

<h2>Edition des modules disponibles</h2>

<h3>Listes de modules enregistré</h3>
<table>
    <thead>
        <tr>
            <td>Module Name</td>
            <td colspan="2">Options</td>
        </tr>
    </thead>
    <tbody class="accordion">
        
<?php
foreach ($modules as $key => $module){
    $name = $module;   
    $id = $key;
    ?>
        <tr>
            <td class="head">
                <?php echo $name;?> 
            </td>    
            <td>            
                <?php echo $this->Html->link('Edit', array('action' => 'admin_edit', $id));?>
            </td>
            <td>
                <?php echo $this->Html->link('Delete', array('action' => 'admin_delete', $id));?>
            </td>
        </tr>
        <tr class="target">
            <td></td>
            <td colspan="1">
                <?php
                // Affiche les sports qui utilise le module
                $moduleSports = $modulesList[$id]['Sport'];
                if (!empty($moduleSports)){
                    foreach ($moduleSports as $sport){
                        echo '<li>'.$sport['name'].'</li>';
                    }
                }
                else{
                    echo 'Aucun sport';
                }
                ?>
            </td>
            <td colspan="1">
                <?php
                // Affiche les sports qui utilise le module
                $moduleInfos= $modulesList[$id]['Module'];
                echo '<p>'.$moduleInfos['description'].'</p>';
                echo '<p>'.$moduleInfos['selectable'].'</p>';
                ?>
            </td>
        </tr>
    <?php
}
?>
    </tbody>
</table>



<h3>Ajouter un module</h3>

<div >
    <?php
    echo $this->Form->create('Module', array('action' => 'admin_add'));
    echo $this->Form->input("Module.parent_id", array(
        'options' => $modules,
    ));   
    echo $this->Form->input("Sport", array(
        'label' => 'Les sports',
        'multiple' => 'checkbox',
    ));        
    echo $this->Form->input("Module.name", array());
    echo $this->Form->input("Module.selectable", array(
        'options' => array(
            0 => 'Non', 
            1 => 'Oui'
        )
    ));
    echo $this->Form->input("Module.description", array(
        'type' => 'textarea'
    ));   
    echo $this->Form->end("Add");
    ?>
</div>